<?php

namespace App\Http\Controllers;

use Redis;
use App\Exceptions\InvalidRequestException;

class CommunityController extends CommonController
{

    public function __construct()
    {
        $this->middleware('validation');
    }

    private static $_validate = [
        'tag' => [
            'type' => 'in:all,recommend',
        ],
    ];

    public function tag()
    {
        $type = request('type', 'all');

        if ($type === 'recommend') {
            return unserialize(Redis::get('api:recommend_tags'));
        }

        $tags = unserialize(Redis::get('api:tags'));

        $returnData = [];
        foreach ($tags as $key => $value) {
            $returnData[] = ['id' => $key, 'name' => $value];
        }

        return $returnData;
    }
}
